function base64_decode (data) {
  //  discuss at: http://phpjs.org/functions/base64_decode/
  // original by: Tyler Akins (http://rumkin.com)
  // improved by: Thunder.m
  // improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  // improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  //    input by: Aman Gupta
  //    input by: Brett Zamir (http://brett-zamir.me)
  // bugfixed by: Onno Marsman
  // bugfixed by: Pellentesque Malesuada
  // bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  //   example 1: base64_decode('S2V2aW4gdmFuIFpvbm5ldmVsZA==');
  //   returns 1: 'Kevin van Zonneveld'
  //   example 2: base64_decode('YQ===');
  //   returns 2: 'a'
  //   example 3: base64_decode('4pyTIMOgIGxhIG1vZGU=');
  //   returns 3: '✓ à la mode'

  var b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='
  var o1, o2, o3, h1, h2, h3, h4, bits, i = 0,
	ac = 0,
	dec = '',
	tmp_arr = []

  if (!data) {
	return data
  }

  data += ''

  do {
	// unpack four hexets into three octets using index points in b64
	h1 = b64.indexOf(data.charAt(i++))
	h2 = b64.indexOf(data.charAt(i++))
	h3 = b64.indexOf(data.charAt(i++))
	h4 = b64.indexOf(data.charAt(i++))

	bits = h1 << 18 | h2 << 12 | h3 << 6 | h4

	o1 = bits >> 16 & 0xff
	o2 = bits >> 8 & 0xff
	o3 = bits & 0xff

	if (h3 == 64) {
	  tmp_arr[ac++] = String.fromCharCode(o1)
	} else if (h4 == 64) {
	  tmp_arr[ac++] = String.fromCharCode(o1, o2)
	} else {
	  tmp_arr[ac++] = String.fromCharCode(o1, o2, o3)
	}
  } while (i < data.length)

  dec = tmp_arr.join('')

  return decodeURIComponent(escape(dec.replace(/\0+$/, '')))
}

function base64_encode (data) {
  //  discuss at: http://phpjs.org/functions/base64_encode/
  // original by: Tyler Akins (http://rumkin.com)
  // improved by: Bayron Guevara
  // improved by: Thunder.m
  // improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  // improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  // improved by: Rafał Kukawski (http://blog.kukawski.pl)
  // bugfixed by: Pellentesque Malesuada
  //   example 1: base64_encode('Kevin van Zonneveld');
  //   returns 1: 'S2V2aW4gdmFuIFpvbm5ldmVsZA=='
  //   example 2: base64_encode('a');
  //   returns 2: 'YQ=='
  //   example 3: base64_encode('✓ à la mode');
  //   returns 3: '4pyTIMOgIGxhIG1vZGU='

  var b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='
  var o1, o2, o3, h1, h2, h3, h4, bits, i = 0,
	ac = 0,
	enc = '',
	tmp_arr = []

  if (!data) {
	return data
  }

  data = unescape(encodeURIComponent(data))

  do {
	// pack three octets into four hexets
	o1 = data.charCodeAt(i++)
	o2 = data.charCodeAt(i++)
	o3 = data.charCodeAt(i++)

	bits = o1 << 16 | o2 << 8 | o3

	h1 = bits >> 18 & 0x3f
	h2 = bits >> 12 & 0x3f
	h3 = bits >> 6 & 0x3f
	h4 = bits & 0x3f

	// use hexets to index into b64, and append result to encoded string
	tmp_arr[ac++] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4)
  } while (i < data.length)

  enc = tmp_arr.join('')

  var r = data.length % 3

  return (r ? enc.slice(0, r - 3) : enc) + '==='.slice(r || 3)
}

//实例化编辑器
//建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('content')就能拿到相关的实例
//var ue = UE.getEditor('content');

var current_editor = UE.getEditor('content',{
	initialFrameHeight:600,
	open_editor: true,
	style_width:360, //样式区宽度像素
	style_url : 'http://www.135editor.com/editor_styles/open?inajax=1&appkey=xxxx'
});


function isFocus(e){
	alert(UE.getEditor('content').isFocus());
	UE.dom.domUtils.preventDefault(e)
}
function setblur(e){
	UE.getEditor('content').blur();
	UE.dom.domUtils.preventDefault(e)
}

function createEditor() {
	enableBtn();
	UE.getEditor('content');
}
function getAllHtml() {
	alert(UE.getEditor('content').getAllHtml())
}
function getContent() {
	console.log(UE.getEditor('content').getContent());
}
function getWxContent() {
	console.log(UE.getEditor('content').getWxContent());
}
function getPlainTxt() {
	var arr = [];
	arr.push("使用editor.getPlainTxt()方法可以获得编辑器的带格式的纯文本内容");
	arr.push("内容为：");
	arr.push(UE.getEditor('content').getPlainTxt());
	alert(arr.join('\n'))
}
function setContent(isAppendTo) {
	var arr = [];
	arr.push("使用editor.setContent('欢迎使用ueditor')方法可以设置编辑器的内容");
	UE.getEditor('content').setContent('欢迎使用ueditor', isAppendTo);
	alert(arr.join("\n"));
}
function setDisabled() {
	UE.getEditor('content').setDisabled('fullscreen');
	disableBtn("enable");
}

function setEnabled() {
	UE.getEditor('content').setEnabled();
	enableBtn();
}

function getText() {
	//当你点击按钮时编辑区域已经失去了焦点，如果直接用getText将不会得到内容，所以要在选回来，然后取得内容
	var range = UE.getEditor('content').selection.getRange();
	range.select();
	var txt = UE.getEditor('content').selection.getText();
	alert(txt)
}

function getContentTxt() {
	var arr = [];
	arr.push("使用editor.getContentTxt()方法可以获得编辑器的纯文本内容");
	arr.push("编辑器的纯文本内容为：");
	arr.push(UE.getEditor('content').getContentTxt());
	alert(arr.join("\n"));
}
function hasContent() {
	var arr = [];
	arr.push("使用editor.hasContents()方法判断编辑器里是否有内容");
	arr.push("判断结果为：");
	arr.push(UE.getEditor('content').hasContents());
	alert(arr.join("\n"));
}
function setFocus() {
	UE.getEditor('content').focus();
}
function deleteEditor() {
	disableBtn();
	UE.getEditor('content').destroy();
}
function disableBtn(str) {
	var div = document.getElementById('btns');
	var btns = UE.dom.domUtils.getElementsByTagName(div, "button");
	for (var i = 0, btn; btn = btns[i++];) {
		if (btn.id == str) {
			UE.dom.domUtils.removeAttributes(btn, ["disabled"]);
		} else {
			btn.setAttribute("disabled", "true");
		}
	}
}
function enableBtn() {
	var div = document.getElementById('btns');
	var btns = UE.dom.domUtils.getElementsByTagName(div, "button");
	for (var i = 0, btn; btn = btns[i++];) {
		UE.dom.domUtils.removeAttributes(btn, ["disabled"]);
	}
}

function getLocalData () {
	alert(UE.getEditor('content').execCommand( "getlocaldata" ));
}

function clearLocalData () {
	UE.getEditor('content').execCommand( "clearlocaldata" );
	alert("已清空草稿箱")
}